var listPage = avalon.define({
	$id: "listPage",
	category: {
		"name": ""
	},
	noData:"",
	solutions: []
});



mui.ready(function() {
	
	var cid=$.getParameter("cid");
	var pageNo = 1;
	var mui_solution=mui('#solutions');
	mui.init({
		pullRefresh: {
			container: "#solutions",
			down: {
				height: 50,
				auto: true,
				contentdown: $.i18n.prop('Pull_down_to_refresh'),
				contentover: $.i18n.prop('Release_to_immediate_refresh'),
				contentrefresh: $.i18n.prop('Loading'),	
				callback: function() {
					listPage.noData="";
					setTimeout(function() {
						pageNo = 1;
						listPage.solutions = [];
						mui.ajax('/solution/list.json', {
							data: {
								categoryId: cid,
								pageNo: pageNo
							},
							dataType: 'json',
							success: function(data) {
								listPage.category = data.category;
								listPage.solutions = data.solutions;
								mui_solution.pullRefresh().endPulldownToRefresh();
								
								if(listPage.solutions.length==0){
									listPage.noData="<img src='../../resources/images/coming_soon.png'>";
								}
								
							}
						});
					}, window.DAHUA_CONFIG.LOADING_TIME);
					
				}
			},
			up: {
				height: 50,
				auto: true,
				contentrefresh: $.i18n.contentRefresh,
				contentnomore: $.i18n.noData,
				callback: function() {
					listPage.noData="";
					setTimeout(function() {
						pageNo=pageNo+1;
						mui.ajax('/solution/list.json', {
							data: {
								categoryId: cid,
								pageNo: pageNo
							},
							dataType: 'json',
							success: function(data) {
								var solutions=listPage.solutions;
								var items=data.solutions;
								avalon.each(items, function(i, item) {
									solutions.push(item);
								});
								listPage.solutions=solutions;
								mui_solution.pullRefresh().endPullupToRefresh(false);
								
								if(listPage.solutions.length==0){
									listPage.noData="<img src='../../resources/images/coming_soon.png'>";
								}
								
							}
						});
					}, window.DAHUA_CONFIG.LOADING_TIME);
	
				}
			}
		}
	});
	
	 

	mui("#solution-list").on('tap', 'a', function() {
		var sid = this.getAttribute('data-id');
		var url = this.getAttribute('href');
		mui.openWindow({
			url: url+"?sid="+sid
		});
	});
	
	

});